import * as api from './api';
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, EditReq, UserPageQuery, UserPageRes } from '@fast-crud/fast-crud';

export default function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
    const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
        return await api.GetList(query);
    };
    const editRequest = async ({ form, row }: EditReq) => {
        form.id = row.id;
        return await api.UpdateObj(form);
    };
    const delRequest = async ({ row }: DelReq) => {
        return await api.DelObj(row.id);
    };

    const addRequest = async ({ form }: AddReq) => {
        return await api.AddObj(form);
    };

    return {
        crudOptions: {
            request: {
                pageRequest,
                addRequest,
                editRequest,
                delRequest,
            },
            columns: {
            meterNo: {
              title: "电表ID",
              type: "text", //字段类型，fs会根据字段类型，生成出一些默认配置
              search: { show: true },
              column: { //表格列的一些配置
                resizable: true,
                width: 200
              }
            },
            paramName: {
              title: "名称",
              type: "text", //字段类型，fs会根据字段类型，生成出一些默认配置
              search: { show: true },
              column: { //表格列的一些配置
                resizable: true,
                width: 200
              }
            },value: {
              title: "度数",
              type: "text", //字段类型，fs会根据字段类型，生成出一些默认配置
              search: { show: true },
              column: { //表格列的一些配置
                resizable: true,
                width: 200
              }
            },unitName: {
              title: "单位",
              type: "text", //字段类型，fs会根据字段类型，生成出一些默认配置
              search: { show: true },
              column: { //表格列的一些配置
                resizable: true,
                width: 200
              }
            }
        },
        },
    };
}